#include <iostream>
#include <vector>
#include<cstring>
using namespace std;
class CTextBlock
{
public:
    CTextBlock(char *str):pText(str){}
    std::size_t length() const;
    char& operator[](std::size_t position) const { return pText[position]; }
private:
    char *pText;
    mutable std::size_t textLength;
    mutable bool lengthIsValid;
};
std::size_t CTextBlock::length() const
{
    if (!lengthIsValid)
    {
        textLength = std::strlen(pText); // error! can't assign to textLength lengthIsValid = true;
        lengthIsValid = true;           // and lengthIsValid in a const } return textLength;
    }
    return textLength;
}
int main()
{
    const CTextBlock cctb("Hello"); // declare constant object
    char *pc = &cctb[0];            // call the const operator[] to get a // pointer to cctb's data
    *pc = 'J';                      // cctb now has the value “Jello”
}